<template>
	<div class="teacher-teacherinformation">
		<Form ref="formValidate" :model="formValidate" :label-width="80" :rules="ruleValidate">
			
			<FormItem label="姓名" prop="teacher_name.zh">
            	<Input v-model="formValidate.teacher_name.zh" placeholder="姓名" style="width:80%"></Input>
        	</FormItem>

			<FormItem label="身份证号" prop="idcard">
				<Input v-model="formValidate.idcard" placeholder="身份证号" style="width:80%"></Input>
			</FormItem>

			<FormItem label="手机号码" prop="telnumber">
				<Input v-model="formValidate.telnumber" placeholder="手机号码" style="width:80%"></Input>
			</FormItem>

			<FormItem label="电子邮箱" prop="email">
				<Input v-model="formValidate.email" placeholder="电子邮箱" style="width:80%"></Input>
			</FormItem>
	
			<FormItem label="性别" prop="gender">
				<Select v-model="formValidate.gender" style="width:80%" placeholder="请选择性别">
					<Option v-for="(item, index) in dataDictionary.gender" :value="item.value_code" :key="index">
						{{ item.dictionary_name.zh ? item.dictionary_name.zh : item.dictionary_name.mn }}
					</Option>
				</Select>
			</FormItem>
	
			<FormItem label="出生日期" prop="birthday">
				<DatePicker v-model="formValidate.birthday" type="datetime" format="yyyy-MM-dd HH:MM:SS" placeholder="请选择参加工作时间" style="width: 200px"></DatePicker>
			</FormItem>
	
			<FormItem label="国籍" prop="nationality">
				<Select v-model="formValidate.nationality" style="width:80%" placeholder="请选择国籍">
					<Option v-for="(item, index) in dataDictionary.nationality" :value="item.value_code" :key="index">
						{{ item.dictionary_name.zh ? item.dictionary_name.zh : item.dictionary_name.mn }}
					</Option>
				</Select>
			</FormItem>
	
			<FormItem label="民族" prop="nation">
				<Select v-model="formValidate.nation" style="width:80%" placeholder="请选择民族">
					<Option v-for="(item, index) in dataDictionary.nation" :value="item.value_code" :key="index">
						{{ item.dictionary_name.zh ? item.dictionary_name.zh : item.dictionary_name.mn }}
					</Option>
				</Select>
			</FormItem>
	
			<FormItem label="政治面貌">
				<Select v-model="formValidate.politicaltype" style="width:80%" placeholder="请选择政治面貌">
					<Option v-for="(item, index) in dataDictionary.politicaltype" :value="item.value_code" :key="index">
						{{ item.dictionary_name.zh ? item.dictionary_name.zh : item.dictionary_name.mn }}
					</Option>
				</Select>
			</FormItem>
	
			<FormItem label="在岗状态">
				<Select v-model="formValidate.workstatus" style="width:80%" placeholder="请选择在岗状态">
					<Option v-for="(item, index) in dataDictionary.workstatus" :value="item.value_code" :key="index">
						{{ item.dictionary_name.zh ? item.dictionary_name.zh : item.dictionary_name.mn }}
					</Option>
				</Select>
			</FormItem>
	
			<FormItem label="人才类型">
				<Select v-model="formValidate.type" style="width:80%" placeholder="请选择人才类型">
					<Option v-for="(item, index) in dataDictionary.type" :value="item.value_code" :key="index">
						{{ item.dictionary_name.zh ? item.dictionary_name.zh : item.dictionary_name.mn }}
					</Option>
				</Select>
			</FormItem>
	
			<FormItem label="最高职称">
				<Select v-model="formValidate.jobtitle" style="width:80%" placeholder="请选择最高职称">
					<Option v-for="(item, index) in dataDictionary.jobtitle" :value="item.value_code" :key="index">
						{{ item.dictionary_name.zh ? item.dictionary_name.zh : item.dictionary_name.mn }}
					</Option>
				</Select>
			</FormItem>
	
			<FormItem label="最高学历">
				<Select v-model="formValidate.education" style="width:80%" placeholder="请选择最高学历">
					<Option v-for="(item, index) in dataDictionary.education" :value="item.value_code" :key="index">
						{{ item.dictionary_name.zh ? item.dictionary_name.zh : item.dictionary_name.mn }}
					</Option>
				</Select>
			</FormItem>
	
			<FormItem label="最高学位">
				<Select v-model="formValidate.degree" style="width:80%" placeholder="请选择最高学位">
					<Option v-for="(item, index) in dataDictionary.degree" :value="item.value_code" :key="index">
						{{ item.dictionary_name.zh ? item.dictionary_name.zh : item.dictionary_name.mn }}
					</Option>
				</Select>
			</FormItem>
	
			<FormItem label="是否硕导">
				<Select v-model="formValidate.mastersupervisor" style="width:80%" placeholder="请选择是否硕导">
					<Option v-for="(item, index) in dataDictionary.mastersupervisor" :value="item.value_code" :key="index">
						{{ item.dictionary_name.zh ? item.dictionary_name.zh : item.dictionary_name.mn }}
					</Option>
				</Select>
			</FormItem>
	
			<FormItem label="是否博导">
				<Select v-model="formValidate.teach" style="width:80%" placeholder="请选择是否博导">
					<Option v-for="(item, index) in dataDictionary.teach" :value="item.value_code" :key="index">
						{{ item.dictionary_name.zh ? item.dictionary_name.zh : item.dictionary_name.mn }}
					</Option>
				</Select>
			</FormItem>
	
			<FormItem label="人才类别(按六支队伍分)">
				<Select v-model="formValidate.talentcategory_six" style="width:80%" placeholder="请选择人才类别(按六支队伍分)">
					<Option v-for="(item, index) in dataDictionary.talentcategorySix" :value="item.value_code" :key="index">
						{{ item.dictionary_name.zh ? item.dictionary_name.zh : item.dictionary_name.mn }}
					</Option>
				</Select>
			</FormItem>
	
			<FormItem label="人才类别(按九支队伍分)">
				<Select v-model="formValidate.talentcategory_nine" style="width:80%" placeholder="请选择人才类别(按九支队伍分)">
					<Option v-for="(item, index) in dataDictionary.talentcategoryNine" :value="item.value_code" :key="index">
						{{ item.dictionary_name.zh ? item.dictionary_name.zh : item.dictionary_name.mn }}
					</Option>
				</Select>
			</FormItem>
	
			<FormItem label="籍贯" style="width:100%;">
				<Select v-model="formValidate.nativeprovince" style="width:30%" @on-change="provinceChange($event, 'jiguan')">
                    <Option v-for="(item, index) in nativeprovinceList" :key="index" :value="item.id">
						{{ item.region_name.zh ? item.region_name.zh : item.region_name.mn }}
					</Option>
				</Select>

				<Select v-model="formValidate.nativecity" style="width:30%" @on-change="cityChange($event, 'jiguan')">
                    <Option v-for="(item, index) in nativecityList" :key="index" :value="item.id">
						{{ item.region_name.zh ? item.region_name.zh : item.region_name.mn }}
					</Option>
				</Select>

				<Select v-model="formValidate.nativecounty" style="width:30%">
                    <Option v-for="(item, index) in nativecountyList" :key="index" :value="item.id">
						{{ item.region_name.zh ? item.region_name.zh : item.region_name.mn }}
					</Option>
				</Select>
			</FormItem>
	
			<FormItem label="出生地" style="width:100%;">
				<Select v-model="formValidate.birthprovince" style="width:30%" @on-change="provinceChange($event, 'chushengdi')">
                    <Option v-for="(item, index) in birthprovinceList" :key="index" :value="item.id">
						{{ item.region_name.zh ? item.region_name.zh : item.region_name.mn }}
					</Option>
				</Select>

				<Select v-model="formValidate.birthcity" style="width:30%" @on-change="cityChange($event, 'chushengdi')">
                    <Option v-for="(item, index) in birthcityList" :key="index" :value="item.id">
						{{ item.region_name.zh ? item.region_name.zh : item.region_name.mn }}
					</Option>
				</Select>

				<Select v-model="formValidate.birthcounty" style="width:30%">
                    <Option v-for="(item, index) in birthcountyList" :key="index" :value="item.id">
						{{ item.region_name.zh ? item.region_name.zh : item.region_name.mn }}
					</Option>
				</Select>
			</FormItem>
	
			<FormItem label="现住址" style="width:100%;">
				<Select v-model="formValidate.cmbprovince3" style="width:30%" @on-change="provinceChange($event, 'xianjudi')">
                    <Option v-for="(item, index) in cmbprovince3List" :key="index" :value="item.id">
						{{ item.region_name.zh ? item.region_name.zh : item.region_name.mn }}
					</Option>
				</Select>

				<Select v-model="formValidate.cmbcity3" style="width:30%" @on-change="cityChange($event, 'xianjudi')">
                    <Option v-for="(item, index) in cmbcity3List" :key="index" :value="item.id">
						{{ item.region_name.zh ? item.region_name.zh : item.region_name.mn }}
					</Option>
				</Select>

				<Select v-model="formValidate.cmbcounty3" style="width:30%">
                    <Option v-for="(item, index) in cmbcounty3List" :key="index" :value="item.id">
						{{ item.region_name.zh ? item.region_name.zh : item.region_name.mn }}
					</Option>
				</Select>
			</FormItem>
	
			<FormItem label="户籍所在地" style="width:100%;">
				<Select v-model="formValidate.cmbprovince2" style="width:30%" @on-change="provinceChange($event, 'hujisuozaidi')">
                    <Option v-for="(item, index) in cmbprovince2List" :key="index" :value="item.id">
						{{ item.region_name.zh ? item.region_name.zh : item.region_name.mn }}
					</Option>
				</Select>

				<Select v-model="formValidate.cmbcity2" style="width:30%" @on-change="cityChange($event, 'hujisuozaidi')">
                    <Option v-for="(item, index) in cmbcity2List" :key="index" :value="item.id">
						{{ item.region_name.zh ? item.region_name.zh : item.region_name.mn }}
					</Option>
				</Select>

				<Select v-model="formValidate.cmbcounty2" style="width:30%">
                    <Option v-for="(item, index) in cmbcounty2List" :key="index" :value="item.id">
						{{ item.region_name.zh ? item.region_name.zh : item.region_name.mn }}
					</Option>
				</Select>
			</FormItem>
	
			<FormItem label="参加工作时间" prop="workdate">
				<DatePicker v-model="formValidate.workdate" type="datetime" format="yyyy-MM-dd HH:MM:SS" placeholder="请选择参加工作时间" style="width: 200px"></DatePicker>
			</FormItem>

			<FormItem label="个人介绍" prop="introduction.zh">
				<Input v-model="formValidate.introduction.zh" type="textarea" :autosize="{minRows: 4,maxRows: 4}" placeholder="个人介绍" style="width:80%">
				</Input>
			</FormItem>
			<FormItem>
				<Button type="primary" @click="handleSubmit('formValidate')" :loading="loadingbtn">提交</Button>
	
				<Button type="ghost" style="margin-left: 8px" @click="handleReset('formValidate')">重置</Button>
			</FormItem>
			<div style="clear:both"></div>
		</Form>
	
	</div>
</template>

<script>
export default {
	props: ['user_id'],
	data() {
		return {
			loadingbtn: false,
			
			formValidate: {
				teacher_name: {
					zh: '',
					mn: '',
					en: '',
				},
				introduction:{
					zh: '',
					mn: '',
					en: '',
				},
				idcard: '',
				email: '',
				telnumber: '',

				gender: '',
				birthday: '',
				nationality: '',
				nation: '',
				politicaltype: '',
				workstatus: '',
				type: '',
				jobtitle: '',
				education: '',
				degree: '',
				mastersupervisor: '',
				teach: '',
				talentcategory_six: '',
				talentcategory_nine: '',

				nativeprovince: '',
				nativecity: '',
				nativecounty: '',

				birthprovince: '',
				birthcity: '',
				birthcounty: '',

				cmbprovince3: '',
				cmbcity3: '',
				cmbcounty3: '',

				cmbprovince2: '',
				cmbcity2: '',
				cmbcounty2: '',

				workdate: ''
			},

			ruleValidate: {
				'teacher_name.zh': [{
						required: true,
						message: '汉文姓名不能为空',
						trigger: 'blur'
					},

				],
				idcard: [
				  {required:true,pattern:/^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/,message:'请输入正确的身份号',trigger:'blur'}
				],
				email: [{
						required: true,
						message: '邮箱不能为空',
						trigger: 'blur'
					},
					{
						type: 'email',
						message: '邮箱格式不正确',
						trigger: 'blur'
					}
				],
				gender: [{
					type: 'string',
					required: true,
					message: '请选择性别',
					trigger: 'change'
				}],
				nation: [{
					type: 'string',
					required: true,
					message: '请选择民族',
					trigger: 'change'
				}],
				nationality: [{
					type: 'string',
					required: true,
					message: '请选择国籍',
					trigger: 'change'
				}],
				workstatus: [{
					type: 'string',
					required: true,
					message: '请选择政治面貌',
					trigger: 'change'
				}],
			},
			
			dataDictionary: {
				nationality: [],			// 国籍
                gender: [],					// 性别
				nation: [],					// 民族
				politicaltype: [],			// 政值面貌
				workstatus: [],				// 在岗状态
				type: [],					// 人才类型
				jobtitle: [],				// 最高职称
				education: [],				// 最高学历
				degree: [],					// 最高学位
				mastersupervisor: [],		// 是否硕导
				teach: [],					// 是否博导
				talentcategorySix: [],		// 人才类别(按六支队伍分)
				talentcategoryNine: [],		// 人才类别(按九支队伍分)
			},

			// 城市三级
			regionData: [],

			// 籍贯
			nativeprovinceList: [],
			nativecityList: [],
			nativecountyList: [],

			// 出生地
			birthprovinceList: [],
			birthcityList: [],
			birthcountyList: [],

			// 现居地
			cmbprovince3List: [],
			cmbcity3List: [],
			cmbcounty3List: [],

			// 户籍所在地
			cmbprovince2List: [],
			cmbcity2List: [],
			cmbcounty2List: [],
		}
	},
	methods: {
		// 表单验证
		handleSubmit(name) {
			this.loadingbtn = true
			this.$refs[name].validate((valid) => {
				if (valid) {
					if (this.user_id) {
						this.editData ()
					} else {
						this.addData ()
					}
				} else {
					this.loadingbtn =false
				}
			})
		},

		addData () {
			this.$http.post('api/teacher/information/save', this.formValidate).then(val => {
				this.$emit('requery', true)
				this.loadingbtn =false
			}).catch(err =>{
				this.loadingbtn =false
			});
		},

		editData () {
			let data = this.formValidate
			data.id = this.user_id
			this.$http.put('api/teacher/information/update', data).then(val => {
				this.$emit('requery', true)
				this.loadingbtn =false
			}).catch(err =>{
				this.loadingbtn =false
			});
		},

		// 重置
		handleReset(name) {
			this.$refs[name].resetFields();
		},

        // 国籍
        nationalityData () {
            let that = this
            let url = 'api/base/dictionary/get/bycode/nationality'
            this.$http.get(url).then((res) => {
                that.dataDictionary.nationality = res.data
            }).catch(err=>{
                
            })
        },

        // 民族
        nationData () {
            let url = 'api/base/dictionary/get/bycode/nation'
            let that = this
            this.$http.get(url).then((res) => {
                that.dataDictionary.nation = res.data
            }).catch(err=>{
                
            })
        },

        // 性别
        genderData () {
            let url = 'api/base/dictionary/get/bycode/gender'
            let that = this
            this.$http.get(url).then((res) => {
                that.dataDictionary.gender = res.data
            }).catch(err=>{
                
            })
        },

        // 政治面貌
        politicaltypeData () {
            let url = 'api/base/dictionary/get/bycode/politicaltype'
            let that = this
            this.$http.get(url).then((res) => {
                that.dataDictionary.politicaltype = res.data
            }).catch(err=>{
                
            })
		},

        // 在岗状态
        workstatusData () {
            let url = 'api/base/dictionary/get/bycode/workstatus'
            let that = this
            this.$http.get(url).then((res) => {
                that.dataDictionary.workstatus = res.data
            }).catch(err=>{
                
            })
		},

        // 人才类型
        talentsTypeData () {
            let url = 'api/base/dictionary/get/bycode/talents_type'
            let that = this
            this.$http.get(url).then((res) => {
                that.dataDictionary.type = res.data
            }).catch(err=>{
                
            })
		},

        // 最高职称
        jobtitleData () {
            let url = 'api/base/dictionary/get/bycode/jobtitle'
            let that = this
            this.$http.get(url).then((res) => {
                that.dataDictionary.jobtitle = res.data
            }).catch(err=>{
                
            })
		},

        // 最高学历
        educationData () {
            let url = 'api/base/dictionary/get/bycode/education'
            let that = this
            this.$http.get(url).then((res) => {
                that.dataDictionary.education = res.data
            }).catch(err=>{
                
            })
		},

        // 最高学位
        degreeData () {
            let url = 'api/base/dictionary/get/bycode/degree'
            let that = this
            this.$http.get(url).then((res) => {
                that.dataDictionary.degree = res.data
            }).catch(err=>{
                
            })
		},

        // 是否硕导
        mastersupervisorData () {
            let url = 'api/base/dictionary/get/bycode/mastersupervisor'
            let that = this
            this.$http.get(url).then((res) => {
                that.dataDictionary.mastersupervisor = res.data
            }).catch(err=>{
                
            })
		},

        // 是否博导
        teachData () {
            let url = 'api/base/dictionary/get/bycode/teach'
            let that = this
            this.$http.get(url).then((res) => {
                that.dataDictionary.teach = res.data
            }).catch(err=>{
                
            })
		},

        // 人才类别(按六支队伍分)
        talentcategorySixData () {
            let url = 'api/base/dictionary/get/bycode/talentcategory_six'
            let that = this
            this.$http.get(url).then((res) => {
                that.dataDictionary.talentcategorySix = res.data
            }).catch(err=>{
                
            })
		},

        // 人才类别(按九支队伍分)
        talentcategoryNineData () {
            let url = 'api/base/dictionary/get/bycode/talentcategory_nine'
            let that = this
            this.$http.get(url).then((res) => {
                that.dataDictionary.talentcategoryNine = res.data
            }).catch(err=>{
                
            })
		},

        /************************************************************
         * 
         * 数据字典获取数据
         * 
         ************************************************************/
        queryDictionary () {
            this.nationalityData ()
            this.nationData ()
            this.genderData ()
			this.politicaltypeData ()
			this.workstatusData ()
			this.talentsTypeData ()
			this.jobtitleData ()
			this.educationData ()
			this.degreeData ()
			this.mastersupervisorData ()
			this.teachData ()
			this.talentcategorySixData ()
			this.talentcategoryNineData ()
		},
		
      
        /************************************************************
         * 
         * 地区
         * 
         ************************************************************/
        queryRegionData () {
            let that = this
            that.$http.get('api/base/regions/get/noPageList').then(val=>{
                let arr = val.data
                let province = arr.filter(el => el.level === 0)
                let city = arr.filter(el => el.level === 1)
                let area = arr.filter(el => el.level === 2)
                that.regionData = val.data

				that.nativeprovinceList = val.data
				that.birthprovinceList = val.data
				that.cmbprovince3List = val.data
				that.cmbprovince2List = val.data
            }).catch(err=>{
            })
		},

		provinceChange (value, type) {
			let that = this

			if (type == 'jiguan') {
				that.nativecountyList = []
			}
			if (type == 'chushengdi') {
				that.birthcountyList = []
			}
			if (type == 'xianjudi') {
				that.cmbcounty3List = []
			}
			if (type == 'hujisuozaidi') {
				that.cmbcounty2List = []
			}

            that.$http.get('api/base/regions/get/noPageList?parent_id=' + value).then(val=>{
				if (type == 'jiguan') {
					that.nativecityList = val.data
				}
				if (type == 'chushengdi') {
					that.birthcityList = val.data
				}
				if (type == 'xianjudi') {
					that.cmbcity3List = val.data
				}
				if (type == 'hujisuozaidi') {
					that.cmbcity2List = val.data
				}
            }).catch(err=>{
            })
		},

		cityChange (value, type) {
			let that = this
            that.$http.get('api/base/regions/get/noPageList?parent_id=' + value).then(val=>{
				if (type == 'jiguan') {
					that.nativecountyList = val.data
				}
				if (type == 'chushengdi') {
					that.birthcountyList = val.data
				}
				if (type == 'xianjudi') {
					that.cmbcounty3List = val.data
				}
				if (type == 'hujisuozaidi') {
					that.cmbcounty2List = val.data
				}
            }).catch(err=>{
            })
		},

		selectData (value) {
			let that = this
            that.$http.get('api/teacher/information/getById/' + value).then(val=>{
				that.formValidate.teacher_name = val.data.teacher_name
				that.formValidate.introduction = val.data.introduction
				that.formValidate.idcard = val.data.idcard
				that.formValidate.email = val.data.email
				that.formValidate.telnumber = val.data.telnumber

				that.formValidate.gender = val.data.gender
				that.formValidate.birthday = val.data.birthday
				that.formValidate.nationality = val.data.nationality
				that.formValidate.nation = val.data.nation
				that.formValidate.politicaltype = val.data.politicaltype
				that.formValidate.workstatus = val.data.workstatus
				that.formValidate.type = val.data.type
				that.formValidate.jobtitle = val.data.jobtitle
				that.formValidate.education = val.data.education
				that.formValidate.degree = val.data.degree
				that.formValidate.mastersupervisor = val.data.mastersupervisor
				that.formValidate.teach = val.data.teach
				that.formValidate.talentcategory_six = val.data.talentcategory_six
				that.formValidate.talentcategory_nine = val.data.talentcategory_nine
				
				that.formValidate.nativeprovince = val.data.nativeprovince
				that.formValidate.nativecity = val.data.nativecity
				that.formValidate.nativecounty = val.data.nativecounty
				
				that.formValidate.birthprovince = val.data.birthprovince
				that.formValidate.birthcity = val.data.birthcity
				that.formValidate.birthcounty = val.data.birthcounty
				
				that.formValidate.cmbprovince3 = val.data.cmbprovince3
				that.formValidate.cmbcity3 = val.data.cmbcity3
				that.formValidate.cmbcounty3 = val.data.cmbcounty3
				
				that.formValidate.cmbprovince2 = val.data.cmbprovince2
				that.formValidate.cmbcity2 = val.data.cmbcity2
				that.formValidate.cmbcounty2 = val.data.cmbcounty2

				that.formValidate.workdate = val.data.workdate

				that.provinceChange (val.data.nativeprovince, 'jiguan')
				that.provinceChange (val.data.birthprovince, 'chushengdi')
				that.provinceChange (val.data.cmbprovince3, 'xianjudi')
				that.provinceChange (val.data.cmbprovince2, 'hujisuozaidi')

				that.cityChange (val.data.nativecity, 'jiguan')
				that.cityChange (val.data.birthcity, 'chushengdi')
				that.cityChange (val.data.cmbcity3, 'xianjudi')
				that.cityChange (val.data.cmbcity2, 'hujisuozaidi')
            }).catch(err=>{
            })
		}
	},

	mounted () {
		this.queryDictionary ()
		this.queryRegionData ()
		if (this.user_id) this.selectData (this.user_id)
	}
}
</script>

<style lang="less">
	.teacher-teacherinformation{
		.ivu-form-item {
			width: 50%;
			float: left;
		}
	}
</style>

